//
//  GCBSearchBar.h
//  LeconsOS
//
//  Created by 李勤超 on 2018/9/19.
//  Copyright © 2018年 江苏乐建网络科技有限公司. All rights reserved.
//

#import <UIKit/UIKit.h>

#define GCBSearchBarHeight 50.0

@class GCBTextField;
@class GCBSearchBar;

typedef NS_ENUM(NSInteger, GCBSearchBarCancelShowType) {
    GCBSearchBarCancelShowTypeNone     = 0,    //  不显示取消按钮，默认值
    GCBSearchBarCancelShowTypeEditing,         //  只在编辑时显示
    GCBSearchBarCancelShowTypeAlways,          //  一直显示
    
    
    
    GCBSearchBarCancelShowTypeScreening  = 50  //  显示成筛选样式
};

@protocol GCBSearchBarDelegate <NSObject>
@optional

- (BOOL)gcbSearchBarShouldBeginEditing:(GCBSearchBar *)searchBar;

- (void)gcbSearchBarDidBeginEditing:(GCBSearchBar *)searchBar;
- (void)gcbSearchBarTextDidChanged:(GCBSearchBar *)searchBar searchText:(NSString *)searchText;
- (void)gcbSearchBarDidEndEditing:(GCBSearchBar *)searchBar;

- (void)gcbSearchBarDidEndEditing:(GCBSearchBar *)searchBar reason:(UITextFieldDidEndEditingReason)reason API_AVAILABLE(ios(10.0));

- (void)gcbSearchBarSearchButtonClicked:(GCBSearchBar *)searchBar;
- (void)gcbSearchBarCancelButtonClicked:(GCBSearchBar *)searchBar;
- (void)gcbSearchBarScreenOutButtonClicked:(GCBSearchBar *)searchBar;

- (BOOL)gcbSearchBar:(GCBSearchBar *)searchBar shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;

@end


/**
 高度 固定为 50.0
 */
@interface GCBSearchBar : UIView


@property (nonatomic, strong, readonly) GCBTextField *textField;

/**
 textField.placeholder  默认 @"搜索"
 */
@property (nonatomic, copy) NSString *placeholder;

/**
 背景色 textField  默认 Color_Background_Base
 */
@property (nonatomic, strong) UIColor *backgroundColor_textField;

@property (nonatomic, copy) NSString *textField_LeftImg;

/**
 textField.font  默认 14
 */
@property (nonatomic, assign) CGFloat font;
/**
 textField提示文字大小 默认 13
 */
@property (nonatomic, assign) CGFloat font_placeholder;

/**
 textField文本颜色  默认 Color_Text_Detail
 */
@property (nonatomic, strong) UIColor *textColor;

/**
 textField提示文字颜色  默认 Color_Text_Detail
 */
@property (nonatomic, strong) UIColor *textColor_placeholder;

/**
 默认 (10, 15, 10, 15)
 */
@property (nonatomic) UIEdgeInsets textFieldInsets;

/**
 returnKeyType
 */
@property (nonatomic) UIReturnKeyType returnKeyType;



#pragma mark -- 取消按钮相关

@property (nonatomic, assign) GCBSearchBarCancelShowType cancelShowsType;

@property (nonatomic, strong) UIButton *cancelButton;

@property (nonatomic, strong) UIImageView *textField_LeftImgView;

/**
 默认 @"取消" 或 @"筛选"
 由 cancelShowsType 决定
 */
@property (nonatomic, copy) NSString *cancelButtonTitle;

/**
 默认 14
 */
@property (nonatomic, assign) CGFloat cancelButtonFont;

/**
 默认 clearColor
 */
@property (nonatomic, strong) UIColor *backgroundColor_cancelButton;

/**
 默认 Color_importantBlue 或 Color_Text_Detail
 由 cancelShowsType 决定
 */
@property (nonatomic, strong) UIColor *textColor_cancelButton;



@property (nonatomic, weak) id <GCBSearchBarDelegate> delegate;


/**
 Description

 @param frame frame的高度固定为  50.0  外部修改无效
 @param placeholder placeholder description
 @param type type description
 @param delegate delegate description
 @return return value description
 */
+ (instancetype)searBarWithFrame:(CGRect)frame
                     placeholder:(NSString *)placeholder
                  cancelShowType:(GCBSearchBarCancelShowType)type
                        delegate:(id)delegate;

/**
 调出键盘
 */
- (void)becomeFirstResponder;

/**
 结束键盘
 */
- (void)resignFirstResponder;

@end

@interface GCBTextField : UITextField


@end
